package Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Service.Servlet;
import vo.User;


@WebServlet("/fun")
public class FunServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Servlet a = new Servlet();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		User str = a.longin(username,password);
		request.getSession().setAttribute("str", str);
		if(str != null){
			if(str.getUsername().equals("admin")){
				request.getRequestDispatcher("abc/welcome.jsp").forward(request, response);
			}else{
				request.getRequestDispatcher("abc/welcome1.jsp").forward(request, response);
			}
		}else{
			response.sendRedirect("index.jsp");
		}
 	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
